GtkIconPaintable: Always recolor when snapshotting.
authorAlexander Larsson <alexl@redhat.com>
Wed, 5 Feb 2020 08:49:23 +0000 (09:49 +0100)
committerAlexander Larsson <alexl@redhat.com>
Thu, 6 Feb 2020 08:38:25 +0000 (09:38 +0100)
It never makes sense to paint a texture that needs recoloring. If
you call the regular snapshot on a symbolic texture we just use the
default recoloring colors.

To support this we also change gtk_css_style_snapshot_icon_paintable()
to call gtk_icon_paintable_snapshot_with_colors() for IconPaintables
so that we get the correct colors, and we make it not emit the color
matrix.

Since we now rely on the icon to do the recoloring we also drop the
recolor argument in gtk_icon_paintable_snapshot_with_colors() as its
not needed anymore.

gtk/gtkiconhelper.c
gtk/gtkicontheme.c
gtk/gtkrender.c
gtk/gtkrendericon.c
gtk/gtkrendericonprivate.h

index 21e6def09a766ea3baee0e7ffae7aea7654e8527..0c8e960d53111b34e4a34bd436df226118869b33 100644 (file)
@@ -223,8 +223,7 @@ gtk_icon_helper_paintable_snapshot (GdkPaintable *paintable,
             gtk_css_style_snapshot_icon_paintable (style,
                                                    snapshot,
                                                    self->paintable,
-                                                   w, h,
-                                                   self->texture_is_symbolic);
+                                                   w, h);
             gtk_snapshot_restore (snapshot);
           }
         else
@@ -232,8 +231,7 @@ gtk_icon_helper_paintable_snapshot (GdkPaintable *paintable,
             gtk_css_style_snapshot_icon_paintable (style,
                                                    snapshot,
                                                    self->paintable,
-                                                   w, h,
-                                                   self->texture_is_symbolic);
+                                                   w, h);
 
           }
 
@@ -280,8 +278,7 @@ gtk_icon_helper_paintable_snapshot (GdkPaintable *paintable,
             gtk_css_style_snapshot_icon_paintable (style,
                                                    snapshot,
                                                    self->paintable,
-                                                   w, h,
-                                                   self->texture_is_symbolic);
+                                                   w, h);
             gtk_snapshot_restore (snapshot);
           }
         else
@@ -289,8 +286,7 @@ gtk_icon_helper_paintable_snapshot (GdkPaintable *paintable,
             gtk_css_style_snapshot_icon_paintable (style,
                                                    snapshot,
                                                    self->paintable,
-                                                   w, h,
-                                                   self->texture_is_symbolic);
+                                                   w, h);
           }
       }
       break;
index 4d2ac88497fb14c3f4d43b3bb9afb1e69843e0ee..9cf4b29068c2d895084ac803a29276a00a5dc9dd 100644 (file)
@@ -3598,25 +3598,9 @@ icon_paintable_snapshot (GdkPaintable *paintable,
                          double        height)
 {
   GtkIconPaintable *icon = GTK_ICON_PAINTABLE (paintable);
-  GdkTexture *texture;
-
-  texture = gtk_icon_paintable_download_texture (icon, NULL);
-  if (texture)
-    {
-      if (icon->desired_scale != 1)
-        {
-          gtk_snapshot_save (snapshot);
-          gtk_snapshot_scale (snapshot, 1.0 / icon->desired_scale, 1.0 / icon->desired_scale);
-        }
 
-      gtk_snapshot_append_texture (snapshot, texture,
-                                   &GRAPHENE_RECT_INIT (0, 0, width * icon->desired_scale, height * icon->desired_scale));
-
-      if (icon->desired_scale != 1)
-        gtk_snapshot_restore (snapshot);
-
-      g_object_unref (texture);
-    }
+  gtk_icon_paintable_snapshot_with_colors (icon, snapshot, width, height,
+                                           NULL, NULL, NULL, NULL);
 }
 
 /**
@@ -3754,7 +3738,7 @@ gtk_icon_paintable_new_for_file (GFile *file,
 
 static GtkIconPaintable *
 gtk_icon_paintable_new_for_pixbuf (GtkIconTheme *icon_theme,
-                         GdkPixbuf    *pixbuf)
+                                   GdkPixbuf    *pixbuf)
 {
   GtkIconPaintable *icon;
   gint width, height, max;
index 840aaa07425d5e3a6c1037975185b2d2e8ca46fe..c11e377aafa653c2ab0ad2447021f95b22102c7b 100644 (file)
@@ -519,8 +519,7 @@ gtk_render_icon (GtkStyleContext *context,
                                          snapshot,
                                          GDK_PAINTABLE (texture),
                                          gdk_texture_get_width (texture),
-                                         gdk_texture_get_height (texture),
-                                         FALSE);
+                                         gdk_texture_get_height (texture));
   node = gtk_snapshot_free_to_node (snapshot);
   if (node == NULL)
     return;
index 7ba2fa83e3411bd5960e3bdf53d4f8ae4cb13933..ddb889642c3ac8836ae0d8c0b7c60a0df61ebfbb 100644 (file)
@@ -93,11 +93,12 @@ gtk_css_style_snapshot_icon_paintable (GtkCssStyle  *style,
                                        GtkSnapshot  *snapshot,
                                        GdkPaintable *paintable,
                                        double        width,
-                                       double        height,
-                                       gboolean      recolor)
+                                       double        height)
 {
   GskTransform *transform;
   gboolean has_shadow;
+  gboolean is_icon_paintable;
+  GdkRGBA fg, sc, wc, ec;
 
   g_return_if_fail (GTK_IS_CSS_STYLE (style));
   g_return_if_fail (snapshot != NULL);
@@ -111,31 +112,19 @@ gtk_css_style_snapshot_icon_paintable (GtkCssStyle  *style,
 
   has_shadow = gtk_css_shadow_value_push_snapshot (style->icon->icon_shadow, snapshot);
 
-  if (recolor)
-    {
-      graphene_matrix_t color_matrix;
-      graphene_vec4_t color_offset;
-      GdkRGBA fg, sc, wc, ec;
-
-      gtk_icon_theme_lookup_symbolic_colors (style, &fg, &sc, &wc, &ec);
+  is_icon_paintable = GTK_IS_ICON_PAINTABLE (paintable);
+  if (is_icon_paintable)
+    gtk_icon_theme_lookup_symbolic_colors (style, &fg, &sc, &wc, &ec);
 
-      if (fg.alpha == 0.0f)
-        goto transparent;
-
-      graphene_matrix_init_from_float (&color_matrix, (float[16]) {
-                                         sc.red - fg.red, sc.green - fg.green, sc.blue - fg.blue, 0,
-                                         wc.red - fg.red, wc.green - fg.green, wc.blue - fg.blue, 0,
-                                         ec.red - fg.red, ec.green - fg.green, ec.blue - fg.blue, 0,
-                                         0, 0, 0, fg.alpha
-                                       });
-      graphene_vec4_init (&color_offset, fg.red, fg.green, fg.blue, 0);
-
-      gtk_snapshot_push_color_matrix (snapshot, &color_matrix, &color_offset);
-    }
+  if (fg.alpha == 0.0f)
+    goto transparent;
 
   if (transform == NULL)
     {
-      gdk_paintable_snapshot (paintable, snapshot, width, height);
+      if (is_icon_paintable)
+        gtk_icon_paintable_snapshot_with_colors (GTK_ICON_PAINTABLE (paintable), snapshot, width, height, &fg, &sc, &wc, &ec);
+      else
+        gdk_paintable_snapshot (paintable, snapshot, width, height);
     }
   else
     {
@@ -146,14 +135,14 @@ gtk_css_style_snapshot_icon_paintable (GtkCssStyle  *style,
       gtk_snapshot_transform (snapshot, transform);
       gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (- width / 2.0, - height / 2.0));
 
-      gdk_paintable_snapshot (paintable, snapshot, width, height);
+      if (is_icon_paintable)
+        gtk_icon_paintable_snapshot_with_colors (GTK_ICON_PAINTABLE (paintable), snapshot, width, height, &fg, &sc, &wc, &ec);
+      else
+        gdk_paintable_snapshot (paintable, snapshot, width, height);
 
       gtk_snapshot_restore (snapshot);
     }
 
-  if (recolor)
-    gtk_snapshot_pop (snapshot);
-
 transparent:
   if (has_shadow)
     gtk_snapshot_pop (snapshot);
index c37be856185972723d8fa8c02aba668a1f59ee8d..a327af50993f400c8d3e56ca682dad0720d3e57e 100644 (file)
@@ -38,8 +38,7 @@ void    gtk_css_style_snapshot_icon_paintable   (GtkCssStyle            *style,
                                                  GtkSnapshot            *snapshot,
                                                  GdkPaintable           *paintable,
                                                  double                  width,
-                                                 double                  height,
-                                                 gboolean                recolor);
+                                                 double                  height);
 
 void    gtk_css_style_render_icon_get_extents   (GtkCssStyle            *style,
                                                  GdkRectangle           *extents,